package com.bz.sso.feign;

import com.bz.dto.CartDto;
import com.bz.pojo.TbUser;
import com.bz.sso.controller.fallback.CommonRedisFeignClientFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 命令规范: 服务名称 + FeignClient
 */
@FeignClient(value = "common-redis",fallbackFactory = CommonRedisFeignClientFallbackFactory.class)
public interface CommonRedisFeignClient {

    //--------------------------- /sso/redis --------------------------
    /**
     * 将用于缓存到Redis中
     * @param tbUser
     * @param userToken
     */
    @PostMapping("/sso/redis/insertUser")
    void insertUser(@RequestBody TbUser tbUser, @RequestParam("userToken") String userToken);

    /**
     * 用户退出登录
     * @param userToken
     */
    @GetMapping("/sso/redis/logout")
    void logout(@RequestParam("userToken")String userToken);

    /**
     * 根据用户token判断用户在redis中是否失效
     * @param userToken
     * @return
     */
    @GetMapping("/checkUserToken")
    public TbUser checkUserToken(@RequestParam("userToken") String userToken);

    //--------------------------- /redis/cart --------------------------
    /**
     * 根据用户ID查询用户购物车
     * @param userId
     * @return
     */
    @GetMapping("/redis/cart/selectCartByUserId")
    CartDto selectCartByUserId(@RequestParam("userId") Long userId);

    /**
     * 根据用户ID查询用户购物车
     * @param cartDto
     */
    @PostMapping("/redis/cart/insertCart")
    void insertCart(@RequestBody CartDto cartDto);
}
